/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketManager.controller;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import ticketManager.ejb.HistoryDAO;
import ticketManager.ejb.ManagerHelper;
import ticketManager.ejb.UserDAO;
import ticketManager.model.ManagerUser;

/**
 *
 * @author luchenyuxx
 */
//@ManagedBean
//@RequestScoped
@Named
@javax.enterprise.context.RequestScoped
public class AssignProblemController {
    @EJB
    ManagerHelper mh;
    @EJB
    HistoryDAO hd;
    @EJB
    UserDAO ud;

    public String assign(Long uid,Long pid){
        System.err.println("assign method has been executed");
        FacesContext ctx = FacesContext.getCurrentInstance();
        Long managerId=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getId();
        mh.assignProblem(managerId,uid,pid);
        hd.assignEvent(managerId, uid, pid);
       // ctx.addMessage(null, new FacesMessage("The problem has been assigned."));
        return "The problem has been assigned to user "+ud.getUserById(uid).getUserName();
    }
}
